package spitfire.ksim.view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import spitfire.ksim.algorithm.FuzzyRule;


/**
 * @author Adam
 *
 */
public class KFuzzyRulePanel extends Plotter2DPanel{

	private static final long serialVersionUID = 6529392651431752957L;
	
	public int WIDTH = 300;
	public int HEIGHT = 100;
	private FuzzyRule rule;

	public KFuzzyRulePanel() {
		setPreferredSize(new Dimension(WIDTH, HEIGHT));
		setDataWindowBottom(0D);
		setDataWindowTop(1D);
		setConnected(true);
		setyAxisLoc(2);
		setAxisStatus(X_AND_Y);
		setRuler(true);
		addComponentListener(new ComponentListener() {
			
			@Override
			public void componentShown(ComponentEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void componentResized(ComponentEvent e) {
				setxAxisLoc(getHeight() - 2);
			}
			
			@Override
			public void componentMoved(ComponentEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void componentHidden(ComponentEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	public void setFuzzyRule(FuzzyRule rule) {
		this.rule = rule;
		setData(rule.getxList(), rule.getyList());
		setDataWindowLeft(rule.getrMin());
		setDataWindowRight(rule.getrMax());
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		if (rule != null) {
			setBackground(Color.WHITE);
		} else {
			setBackground(Color.LIGHT_GRAY);
		}
		super.paintComponent(g);
	}
}
